<?php


namespace app\common\facade\auth;

use app\common\service\auth\AuthAdminService;
use app\common\service\auth\AuthAgentService;
use app\common\service\auth\AuthApiService;
use app\common\service\auth\AuthBase;
use app\common\service\auth\AuthOpenService;
use app\common\service\auth\AuthPubService;
use app\common\service\auth\AuthUnitService;
use app\common\service\auth\AuthYmshService;
use app\model\Admin;
use app\model\MobileUser;
use think\Exception;
use think\Facade;

/**
 * Class AuthYm
 * @package app\common\facade\auth
 *
 * @method static Admin|MobileUser user() 用户信息
 * @method static id() 用户Id 一般指h5的用户
 * @method static attempt($params) 验证信息
 * @method static login($params) 登录
 * @method static platform() 平台属性 只有两个值： admin 或者 agent
 * @method static from() 哪个应用  admin, ymhc
 *
 *
 * 对接有美生活
 * @method static object merchant() 商户信息
 * @method static int merchantId() 商户id
 * @method static bool isAdmin() 是否为有美的总后台
 * @method static bool isMerchant()  是否为商户账号
 * @method static bool isLogin()  是否验证登录了
 * @method static bool allBindAgentIds()  所有绑定的代理商id
 *
 * 用户请求时
 * @method static attemptChannel()  用户请求验证渠道是否存在
 * @method static channelId()  获取渠道id
 * @method static agentId()  获取渠道id
 *
 *
 * 总后台
 * @method static permissions()  获取所有权限 如果要区分菜单还是接口请用 数组集合处理 collect($data)->where('type',\app\model\AdminPermission::TYPE_MENU)
 */
class Auth extends Facade
{

    protected static function getFacadeClass()
    {
        switch (app('http')->getName()) {
            case 'ymsh':
                return AuthYmshService::class;
            case 'agent':
                return AuthAgentService::class;
            case 'admin':
                return AuthAdminService::class;
            case 'api':
                return AuthApiService::class;
            case 'phpunit':
                return AuthUnitService::class;
            case 'pub':
                return AuthPubService::class;
            case 'app':
                $from = input('from', '');
                switch ($from) {
                    case FROM_APP_ADMIN:
                        return AuthAdminService::class;
                    case FROM_APP_AGENT:
                        return AuthAgentService::class;
                    case FROM_APP_API:
                        return AuthApiService::class;
                    case 'open':
                    case 'open_platform':
                        return AuthOpenService::class;
                    default:
                        throw new Exception('api渠道来源不存在');
                }
            default:
                return AuthBase::class;
        }

    }

}